<?php
$js_sign = C('jssign');
$cardid = C('cardid');
$openid = C('openid');
$cardsign = C('cardsign');
?>
<?php if($cardid===1) { // 已经领取过??>
<img src="views/statics/image/end.jpg"/>
<?php exit;} ?>
<a id="addCard"><img src="views/statics/image/get.jpg"></a>
<script>
var openid = '<?php echo $openid;?>';
var cardid = '<?php echo $cardid;?>';
  wx.config({
      debug: false,
      appId: '<?php echo $js_sign['appId']; ?>', // 必填，公众号的唯一标识
      timestamp: <?php echo $js_sign['timestamp']; ?>, // 必填，生成签名的时间戳
      nonceStr: '<?php echo $js_sign['nonceStr']; ?>', // 必填，生成签名的随机串
      signature: '<?php echo $js_sign['signature']; ?>', // 必填，签名，见附录1
      jsApiList: ['addCard']
  });

function addCard() {
    $.post('./?do=cardlog', {openid:openid, cardid:cardid}, function(d){
        if(d==1) {
            alert('参数有误');
            return;
        }
        wx.addCard({
          cardList: [
            {
                cardId: cardid,
                    cardExt: '{"code": "", "openid": "", "timestamp": "<?php echo $cardsign['timestamp']?>", "signature":"<?php echo $cardsign['cardSign']?>"}'
            }
          ],
          success: function (res) {
            alert('领取成功');
            console.log(res)
            //alert('已添加卡券：' + JSON.stringify(res.cardList));
          }
        });    
    })
    
}

 wx.ready(function () {
  // 12 微信卡券接口
  // 12.1 添加卡券
  $('#addCard').on('click', function () {
      addCard();
  });
  
});
wx.error(function (res) {
    console.log(res);
  //alert(res.errMsg);
});
</script>
</html>
